using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VEKGIP
    {
        public DataRow Convert2EKGIP(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryEKGIP(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["EKGMANDANT"] = " ".PadRight(2 ); 
         dwReturn["EKGGIPKRS"] = " ".PadRight(2 ); 
         dwReturn["EKGGIPLFD"] = " ".PadRight(6 ); 
         dwReturn["EKGGIPPOS"] = " ".PadRight(4 ); 
         dwReturn["EKGAENZL"] = " ".PadRight(0 ); 
         dwReturn["EKGAENB"] = " ".PadRight(8 ); 
         dwReturn["EKGAEND"] = " ".PadRight(0 ); 
         dwReturn["EKGNEUB"] = " ".PadRight(8 ); 
         dwReturn["EKGNEUD"] = " ".PadRight(0 ); 
         dwReturn["EKGARTGR"] = " ".PadRight(1 ); 
         dwReturn["EKGMEEH"] = " ".PadRight(3 ); 
         dwReturn["EKGMEEHGRP"] = " ".PadRight(1 ); 
         dwReturn["EKGMEEHFKT"] = " ".PadRight(12 ); 
         dwReturn["EKGBRUTTO"] = " ".PadRight(0 ); 
         dwReturn["EKGNETTO"] = " ".PadRight(0 ); 
         dwReturn["EKGHANDEL"] = " ".PadRight(0 ); 
         dwReturn["EKGTARA"] = " ".PadRight(0 ); 
         dwReturn["EKGMETER"] = " ".PadRight(0 ); 
         dwReturn["EKGSTUECKE"] = " ".PadRight(0 ); 
         dwReturn["EKGPTYP"] = " ".PadRight(4 ); 
         dwReturn["EKGPANZ"] = " ".PadRight(0 ); 
         dwReturn["EKGLIEFNR"] = " ".PadRight(8 ); 
         dwReturn["EKGLIEFSCH"] = " ".PadRight(10 ); 
         dwReturn["EKGLIEFDAT"] = " ".PadRight(0 ); 
         dwReturn["EKGSTATUS"] = " ".PadRight(2 ); 
         dwReturn["EKGAUFKRS"] = " ".PadRight(2 ); 
         dwReturn["EKGAUFLFD"] = " ".PadRight(6 ); 
         dwReturn["EKGAUFPOS"] = " ".PadRight(3 ); 
         dwReturn["EKGERLKZ"] = " ".PadRight(1 ); 
         dwReturn["EKGKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["EKGWERK"] = " ".PadRight(3 ); 
         dwReturn["EKGABT"] = " ".PadRight(3 ); 
         dwReturn["EKGWAKZ"] = " ".PadRight(1 ); 
         dwReturn["EKGART"] = " ".PadRight(20 ); 
         dwReturn["EKGVAR"] = " ".PadRight(3 ); 
         dwReturn["EKGFARBE"] = " ".PadRight(10 ); 
         dwReturn["EKGDESS"] = " ".PadRight(10 ); 
         dwReturn["EKGCOL"] = " ".PadRight(10 ); 
         dwReturn["EKGBESCH"] = " ".PadRight(10 ); 
         dwReturn["EKGZUSTAND"] = " ".PadRight(4 ); 
         dwReturn["EKGGROE"] = " ".PadRight(7 ); 
         dwReturn["EKGAUFM"] = " ".PadRight(2 ); 
         dwReturn["EKGHUELTYP"] = " ".PadRight(6 ); 
         dwReturn["EKGSTAUSER"] = " ".PadRight(8 ); 
         dwReturn["EKGFILLER"] = " ".PadRight(72 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapEKGIP(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveEKGIP(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryEKGIP(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapEKGIP(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertEKGIP(dwLocal, ITXDBVERSION);
            }
            UpdateEKGIP(dwLocal);
        }
        public void InsertEKGIP(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO EKGIP(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryEKGIP(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM EKGIP WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM EKGIP  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "EKGIP";
            Return = Result;
            return Return;
        }
        public void DeleteEKGIP(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM EKGIP   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateEKGIP(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE EKGIP SET "
                    +"EKGMANDANT= :EKGMANDANT,"
                    +"EKGGIPKRS= :EKGGIPKRS,"
                    +"EKGGIPLFD= :EKGGIPLFD,"
                    +"EKGGIPPOS= :EKGGIPPOS,"
                    +"EKGAENZL= :EKGAENZL,"
                    +"EKGAENB= :EKGAENB,"
                    +"EKGAEND= :EKGAEND,"
                    +"EKGNEUB= :EKGNEUB,"
                    +"EKGNEUD= :EKGNEUD,"
                    +"EKGARTGR= :EKGARTGR,"
                    +"EKGMEEH= :EKGMEEH,"
                    +"EKGMEEHGRP= :EKGMEEHGRP,"
                    +"EKGMEEHFKT= :EKGMEEHFKT,"
                    +"EKGBRUTTO= :EKGBRUTTO,"
                    +"EKGNETTO= :EKGNETTO,"
                    +"EKGHANDEL= :EKGHANDEL,"
                    +"EKGTARA= :EKGTARA,"
                    +"EKGMETER= :EKGMETER,"
                    +"EKGSTUECKE= :EKGSTUECKE,"
                    +"EKGPTYP= :EKGPTYP,"
                    +"EKGPANZ= :EKGPANZ,"
                    +"EKGLIEFNR= :EKGLIEFNR,"
                    +"EKGLIEFSCH= :EKGLIEFSCH,"
                    +"EKGLIEFDAT= :EKGLIEFDAT,"
                    +"EKGSTATUS= :EKGSTATUS,"
                    +"EKGAUFKRS= :EKGAUFKRS,"
                    +"EKGAUFLFD= :EKGAUFLFD,"
                    +"EKGAUFPOS= :EKGAUFPOS,"
                    +"EKGERLKZ= :EKGERLKZ,"
                    +"EKGKUNDNR= :EKGKUNDNR,"
                    +"EKGWERK= :EKGWERK,"
                    +"EKGABT= :EKGABT,"
                    +"EKGWAKZ= :EKGWAKZ,"
                    +"EKGART= :EKGART,"
                    +"EKGVAR= :EKGVAR,"
                    +"EKGFARBE= :EKGFARBE,"
                    +"EKGDESS= :EKGDESS,"
                    +"EKGCOL= :EKGCOL,"
                    +"EKGBESCH= :EKGBESCH,"
                    +"EKGZUSTAND= :EKGZUSTAND,"
                    +"EKGGROE= :EKGGROE,"
                    +"EKGAUFM= :EKGAUFM,"
                    +"EKGHUELTYP= :EKGHUELTYP,"
                    +"EKGSTAUSER= :EKGSTAUSER,"
                    +"EKGFILLER= :EKGFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("EKGMANDANT", OracleType.NVarChar).Value = dwData["EKGMANDANT"].ToString(); 
          or1.Parameters.Add("EKGGIPKRS", OracleType.NVarChar).Value = dwData["EKGGIPKRS"].ToString(); 
          or1.Parameters.Add("EKGGIPLFD", OracleType.NVarChar).Value = dwData["EKGGIPLFD"].ToString(); 
          or1.Parameters.Add("EKGGIPPOS", OracleType.NVarChar).Value = dwData["EKGGIPPOS"].ToString(); 
          or1.Parameters.Add("EKGAENZL", OracleType.NVarChar).Value = dwData["EKGAENZL"].ToString(); 
          or1.Parameters.Add("EKGAENB", OracleType.NVarChar).Value = dwData["EKGAENB"].ToString(); 
          or1.Parameters.Add("EKGAEND", OracleType.NVarChar).Value = dwData["EKGAEND"].ToString(); 
          or1.Parameters.Add("EKGNEUB", OracleType.NVarChar).Value = dwData["EKGNEUB"].ToString(); 
          or1.Parameters.Add("EKGNEUD", OracleType.NVarChar).Value = dwData["EKGNEUD"].ToString(); 
          or1.Parameters.Add("EKGARTGR", OracleType.NVarChar).Value = dwData["EKGARTGR"].ToString(); 
          or1.Parameters.Add("EKGMEEH", OracleType.NVarChar).Value = dwData["EKGMEEH"].ToString(); 
          or1.Parameters.Add("EKGMEEHGRP", OracleType.NVarChar).Value = dwData["EKGMEEHGRP"].ToString(); 
          or1.Parameters.Add("EKGMEEHFKT", OracleType.NVarChar).Value = dwData["EKGMEEHFKT"].ToString(); 
          or1.Parameters.Add("EKGBRUTTO", OracleType.NVarChar).Value = dwData["EKGBRUTTO"].ToString(); 
          or1.Parameters.Add("EKGNETTO", OracleType.NVarChar).Value = dwData["EKGNETTO"].ToString(); 
          or1.Parameters.Add("EKGHANDEL", OracleType.NVarChar).Value = dwData["EKGHANDEL"].ToString(); 
          or1.Parameters.Add("EKGTARA", OracleType.NVarChar).Value = dwData["EKGTARA"].ToString(); 
          or1.Parameters.Add("EKGMETER", OracleType.NVarChar).Value = dwData["EKGMETER"].ToString(); 
          or1.Parameters.Add("EKGSTUECKE", OracleType.NVarChar).Value = dwData["EKGSTUECKE"].ToString(); 
          or1.Parameters.Add("EKGPTYP", OracleType.NVarChar).Value = dwData["EKGPTYP"].ToString(); 
          or1.Parameters.Add("EKGPANZ", OracleType.NVarChar).Value = dwData["EKGPANZ"].ToString(); 
          or1.Parameters.Add("EKGLIEFNR", OracleType.NVarChar).Value = dwData["EKGLIEFNR"].ToString(); 
          or1.Parameters.Add("EKGLIEFSCH", OracleType.NVarChar).Value = dwData["EKGLIEFSCH"].ToString(); 
          or1.Parameters.Add("EKGLIEFDAT", OracleType.NVarChar).Value = dwData["EKGLIEFDAT"].ToString(); 
          or1.Parameters.Add("EKGSTATUS", OracleType.NVarChar).Value = dwData["EKGSTATUS"].ToString(); 
          or1.Parameters.Add("EKGAUFKRS", OracleType.NVarChar).Value = dwData["EKGAUFKRS"].ToString(); 
          or1.Parameters.Add("EKGAUFLFD", OracleType.NVarChar).Value = dwData["EKGAUFLFD"].ToString(); 
          or1.Parameters.Add("EKGAUFPOS", OracleType.NVarChar).Value = dwData["EKGAUFPOS"].ToString(); 
          or1.Parameters.Add("EKGERLKZ", OracleType.NVarChar).Value = dwData["EKGERLKZ"].ToString(); 
          or1.Parameters.Add("EKGKUNDNR", OracleType.NVarChar).Value = dwData["EKGKUNDNR"].ToString(); 
          or1.Parameters.Add("EKGWERK", OracleType.NVarChar).Value = dwData["EKGWERK"].ToString(); 
          or1.Parameters.Add("EKGABT", OracleType.NVarChar).Value = dwData["EKGABT"].ToString(); 
          or1.Parameters.Add("EKGWAKZ", OracleType.NVarChar).Value = dwData["EKGWAKZ"].ToString(); 
          or1.Parameters.Add("EKGART", OracleType.NVarChar).Value = dwData["EKGART"].ToString(); 
          or1.Parameters.Add("EKGVAR", OracleType.NVarChar).Value = dwData["EKGVAR"].ToString(); 
          or1.Parameters.Add("EKGFARBE", OracleType.NVarChar).Value = dwData["EKGFARBE"].ToString(); 
          or1.Parameters.Add("EKGDESS", OracleType.NVarChar).Value = dwData["EKGDESS"].ToString(); 
          or1.Parameters.Add("EKGCOL", OracleType.NVarChar).Value = dwData["EKGCOL"].ToString(); 
          or1.Parameters.Add("EKGBESCH", OracleType.NVarChar).Value = dwData["EKGBESCH"].ToString(); 
          or1.Parameters.Add("EKGZUSTAND", OracleType.NVarChar).Value = dwData["EKGZUSTAND"].ToString(); 
          or1.Parameters.Add("EKGGROE", OracleType.NVarChar).Value = dwData["EKGGROE"].ToString(); 
          or1.Parameters.Add("EKGAUFM", OracleType.NVarChar).Value = dwData["EKGAUFM"].ToString(); 
          or1.Parameters.Add("EKGHUELTYP", OracleType.NVarChar).Value = dwData["EKGHUELTYP"].ToString(); 
          or1.Parameters.Add("EKGSTAUSER", OracleType.NVarChar).Value = dwData["EKGSTAUSER"].ToString(); 
          or1.Parameters.Add("EKGFILLER", OracleType.NVarChar).Value = dwData["EKGFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
